﻿#include "animationManager_Practice.h"


AnimationManager_Practice& AnimationManager_Practice::I(){

    static AnimationManager_Practice instance;
    return instance;
}

AnimationManager_Practice::AnimationManager_Practice()
{
    _state = new AnimationState_Practice();
    _controller = new AnimationController_Practice(_state);
}

AnimationManager_Practice::~AnimationManager_Practice()
{
}

QStringList AnimationManager_Practice::getTargetStatus(){
    QStringList values;
     for (const QVariant &value : StaticProperties::practiceTargetStatus.values()) {
         values.append(value.toString());
     }
    return values;
}


QVariantMap AnimationManager_Practice::requestInfo(){
    if(!_controller){  __LOG_ERROR("controller=nullptr");   return QVariantMap();   }
    return _controller->requestInfo();
}


void AnimationManager_Practice::oneButtonInTarget(){

    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }

    _state->turnWheel(0);
    _state->setBrakeState(0);
    _state->moveBar(0);
    _state->setBrakeState(1);
}
void AnimationManager_Practice::oneButtonOutTarget(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setBrakeState(0);
    _state->moveBar(1);
    _state->setBrakeState(1);
    _state->turnWheel(1);
}


void AnimationManager_Practice::feedPortUp(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->moveFeedPort(0);
}
void AnimationManager_Practice::feedPortDown(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->moveFeedPort(1);
}

void AnimationManager_Practice::barMoveLeft(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->moveBar(0);
}
void AnimationManager_Practice::barMoveRight(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->moveBar(1);
}
void AnimationManager_Practice::turnWheelLeft(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->turnWheel(0);
}
void AnimationManager_Practice::turnWheelDown(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->turnWheel(1);
}
void AnimationManager_Practice::openPump1(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setPump1State(1);
}
void AnimationManager_Practice::closePump1(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setPump1State(0);
}
void AnimationManager_Practice::openPump2(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setPump2State(1);
}
void AnimationManager_Practice::closePump2(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setPump2State(0);
}
void AnimationManager_Practice::reset(){
    _state->reset();
}
void AnimationManager_Practice::openBlowTarget(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setBlowTargetState(1);
}
void AnimationManager_Practice::closeBlowTarget(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setBlowTargetState(0);
}
void AnimationManager_Practice::openBrake(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setBrakeState(1);
}
void AnimationManager_Practice::closeBrake(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setBrakeState(0);
}
void AnimationManager_Practice::openPumpHe(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setPumpN2State(1);
}
void AnimationManager_Practice::closePumpHe(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setPumpN2State(0);
}
void AnimationManager_Practice::openAbsorb(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setAbsorbState(1);
}
void AnimationManager_Practice::closeAbsorb(){
    if(!_state){  __LOG_ERROR("state=nullptr");   return;   }
    _state->setAbsorbState(0);
}

QVariantMap AnimationManager_Practice::getCheckInfo(int pageIdx){
//    qDebug() << "pageIdx" << pageIdx;
    if(pageIdx == 1){
        return StaticProperties::releasseTargetStatus;
    }else if(pageIdx == 2){
        return StaticProperties::practiceTargetStatus;
    }else if(pageIdx == 3){
        return StaticProperties::shiftingTargetStatus;
    }else if(pageIdx == 4){
        return StaticProperties::purifyingStatus;
    }
    else{
        return StaticProperties::releasseTargetStatus;
    }
}
